module MC.View {
	export class AddNews {
		public constructor() {
			this.init();
		}
		private id: string = '0';
        private pic = new MC.View.PhotoClip();
		private init() {
			$('#addJob2').on('click', () => {
				MC.click(() => {
					this.saveNews();
				});
			});


			$('#fengmian .pic').on('click', () => {

                this.pic.selPic( (url:any)=>{
                    $('#fengmian .img').attr('src', url.img);
                    $('.addNews__pichide').val(url.img);
                    $('#addNewsDetail .bFileDiv .spantitle').hide();
                });

				/*
				MC.API.UpPic((url: string) => {
					$('#fengmian .img').attr('src', url);
					$('.addNews__pichide').val(url);
					$('#addNewsDetail .bFileDiv .spantitle').hide();
				});*/


			});



		}
		private saveNews() {
			let addNews__title = $('.addNews__title').val();
			let addNews__pichide = $('.addNews__pichide').val();
			let addNewsDetailTextarea = $('#addNewsDetailTextarea').val();
			if (addNews__title == '') {
				MC.msg.alert("标题必须输入");
				return;
			}
			if (addNews__title.length > 32) {
				MC.msg.alert("标题字节数太多了,不能超过32个");
				return;
			}
			if (addNews__pichide == '') {
				MC.msg.alert("封面图必须上传");
				return;
			}
			if (addNewsDetailTextarea == '') {
				MC.msg.alert("内容必须输入");
				return;
			}
			MC.apiD('/api/news/add', {
				title: addNews__title,
				thumb: addNews__pichide,
				content: addNewsDetailTextarea,
			}, (data: any) => {
				console.log(data);
				window.open('/h5/news/newsShow.html?newsShowId=' + data.id, '_self');
			});
		}
	}
}